/**
 * @author daniele.gili@usi.ch
 */

package ch.usi.inf.pf2;

import java.awt.Graphics;
import java.util.ArrayList;
import java.util.Timer;

class CommonGate extends ActionDelay implements CommonGateDraw {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected ActionDelay taskPerformer;
	protected int actualIndex = 0;
	protected Integer actualValue = null;
	protected static Timer myTimer = new Timer();
	protected Integer outputValue;

	// to mod

	protected int pos = 0;

	protected int x = 30;
	protected int y = 30;

	protected int width = 50;
	protected int height = 50;
	
	protected int signalCounter;

	// common things present in all gates. Some of the method are rewritten in
	// the gates class

	// input list
	protected ArrayList<Input> inputList = new ArrayList<Input>();
	protected Output output;
	
	protected int timer = 1;
	
	public void setIndex(int i ){
		actualIndex = i;
	}
	
	// method to return the actual value;
	public Integer getValue(int index) {
		return actualValue;
	}
	


	
	
	public String getGateValue(){
		try {
			return (""+(int)actualValue);
		}
		catch(NullPointerException e){
			return ("None");
		}
	}

	// method to compute a new value (it does not return it)
	public void setNewValue() {
	};

	public void setNewTime(int newTimer) {
		this.timer = newTimer;
		myTimer.cancel();
		myTimer = new Timer();
		myTimer.schedule(new ActionDelay(this), 0, timer);
	}

	public void compute() {

	}

	// method to set the input port;
	public void setInput(Input in) {
		inputList.add(in);
	}

	public void setOutput(Output out) {
		output = out;
	}

	public int getNumberInput() {
		return inputList.size();
	}

	public ArrayList<Input> getInputs() {
		return inputList;
	}

	public void stopDelay(Timer time) {
		time.cancel();
	}

	@Override
	public void draw(Graphics g) {
		g.drawOval(20, 20, 200, 100);
	}

	@Override
	public boolean contains(final int x, final int y) {
		return x >= this.x && x <= this.x + width && y >= this.y
				&& y <= this.y + height;
	}

	public void setNewAttributes(final int x, final int y) {
		this.x = this.x+x;
		this.y = this.y+y;
	}

	public int getHeight() {
		return this.height;
	}

	public int getWidth() {
		return this.width;
	}


	public Timer getMyTimer() {
		return myTimer;
	}

	public void setMyTimer(Timer myTimer) {
		this.myTimer = myTimer;
	}

	public int getTimer() {
		return timer;
	}

	public void setTimer(int timer) {
		this.timer = timer;
	}

	public int getIndex() {
		return pos;
	}

	public void setPos(int pos) {
		this.pos = pos;
	}


}
